﻿<Window x:Class="Hyperstore.Samples.LibrarySample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="430" Width="588">
    <Window.Resources>
        <ControlTemplate x:Key="InputErrorTemplate">
            <DockPanel>
                <Ellipse DockPanel.Dock="Right" Margin="2,0" 
                    ToolTip="{Binding AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=errorAdorner}"
                    Width="10" Height="10">
                    <Ellipse.Fill>
                        <LinearGradientBrush>
                            <GradientStop Color="#11FF1111" Offset="0" />
                            <GradientStop Color="#FFFF0000" Offset="1" />
                        </LinearGradientBrush>
                    </Ellipse.Fill>
                </Ellipse>
                <AdornedElementPlaceholder x:Name="errorAdorner" />
            </DockPanel>
        </ControlTemplate>

        <Style TargetType="TextBox">
            <Setter Property="Validation.ErrorTemplate" Value="{StaticResource InputErrorTemplate}" />            
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="3*"/>
            <RowDefinition Height="35*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button Margin="5 5 0 5" Command="{Binding UndoCommand}" Content="Undo">                
            </Button>
            <Button Margin="5" Command="{Binding RedoCommand}" Content="Redo">
                
            </Button>
        </StackPanel>
        <DataGrid Margin="5" IsReadOnly="True" ItemsSource="{Binding Library.AvalaibleBooks}" SelectedValue="{Binding SelectedBook}" Grid.Row="1" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Title}" Header="Title"/>
                <DataGridTemplateColumn Header="Copies">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Border>
                                <TextBlock x:Name="templateTextBlock" Text="{Binding Path=Copies, NotifyOnTargetUpdated=True}" Background="Transparent"/>
                            </Border>
                            <DataTemplate.Triggers>
                                <EventTrigger RoutedEvent="Binding.TargetUpdated">
                                    <BeginStoryboard>
                                        <Storyboard AutoReverse="True">
                                            <ColorAnimation Storyboard.TargetName="templateTextBlock" Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)" To="Red" Duration="0:0:.5"  />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        <DataGrid Margin="5" IsReadOnly="True" ItemsSource="{Binding Library.Members}" Grid.Column="1" AutoGenerateColumns="False" SelectedValue="{Binding SelectedMember}" Grid.Row="1">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Name}" Header="Member" Width="*"/>
            </DataGrid.Columns>
        </DataGrid>
        <DataGrid Margin="5" Grid.Column="2" IsReadOnly="True" ItemsSource="{Binding SelectedMember.Loans}" SelectedValue="{Binding SelectedBook}" AutoGenerateColumns="False" Grid.Row="1">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Book.Title}" Header="Member" Width="*"/>
                <DataGridTextColumn Binding="{Binding Member.Name}" Header="Member" Width="*"/>
            </DataGrid.Columns>
        </DataGrid>
        <Button Content="Create Loan" HorizontalAlignment="Left" Margin="5" Grid.Row="2" VerticalAlignment="Top" Width="75" Command="{Binding CreateLoanCommand}" Grid.Column="2"/>
        <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="5">
            <TextBlock Text="Copies :" VerticalAlignment="Center"/>
            <TextBox Text="{Binding SelectedBook.Copies, Mode=TwoWay}" Width="50" Margin="5 0" />
        </StackPanel>
    </Grid>
</Window>
